*Fetch data
use new_opportunity.dta,clear

*** Indicator for complete cases
generate complete=0.
replace complete=1 if male~=. & agecat~=. & class~=. & educ~=. & erp~=.

** Country weights
bysort complete country: gen cowe=(50276/7)/_N
replace cowe=. if complete==0


** Voter weights
bysort complete country year: gen elecwe=(50276/7)/_N
replace elecwe=. if complete==0


* Election ID
gen election =year*10+country


* Right2 is computed from CMP data as
* right2=per109-per107+per601-per602+per605+per608-per607.

char agecat[omit] 6
*Wir lassen die aeltesten weg
char class[omit] 6
*Wir lassen die unklassifizierten weg
char educ[omit]4
*Wir lassen die am h�chsten gebildeten weg


* Generate dummies

*  Countries (using W Germany as reference)
gen austria = country==1
gen belgium = country==2
gen denmark = country==3
gen france  = country==4
gen germany = country==6
gen italy   = country==7
gen norway  = country==9

lab var austria "Austria"
lab var belgium "Belgium"
lab var denmark "Denmark"
lab var france "France"
lab var italy "Italy"
lab var germany "Germany"
lab var norway "Norway"
	
	


* Social class
gen profmanager = class==1
gen routnonman  = class==2
gen selfemployed = class ==3
gen skilledmanual = class == 4
gen unskilledmanual = class == 5
gen unclassified= class ==6


	
lab var profmanager "Professionals/Managers"
lab var routnonman "Routine Non-Manual"
lab var selfemployed "Selfemployed"
lab var skilledmanual "Skilled Manual"
lab var unskilledmanual "Unskilled Manual"
lab var unclassified "Unclassified"

* Single dummy for workers (skilled/unskilled)
gen manual = class == 4 | class == 5
lab var manual "Manual"
	
	
* Education 

gen noeducprimary = educ ==1
gen midschool = educ ==2
gen secondaryschool = educ ==3
gen university = educ ==4

lab var noeducprimary "No/Primary Education"
lab var midschool "Mid-School"
lab var secondaryschool "Secondary School"
lab var university "University"
	
* Age

gen ageupto24 = agecat == 1
gen age25to34 = agecat == 2
gen age35to44 = agecat == 3
gen age45to54 = agecat == 4
gen age55to64 = agecat == 5
gen age65andover = agecat == 6  

lab var ageupto24 "Age: -24"
lab var age25to34 "Age: 25-34"
lab var age35to44 "Age: 35-44"
lab var age45to54 "Age: 45-54"
lab var age55to64 "Age: 55-64"
lab var age65andover "Age 65++"

* Disproportionality (taken from Carter's monograph)
gen ndisp=-99

replace ndisp = 2.48 if country==1 & year == 1986
replace ndisp = 0.91 if country==1 & year == 1990
replace ndisp = 2.08 if country==1 & year == 1994
replace ndisp = 1.18 if country==1 & year == 1995
replace ndisp = 1.07 if country==1 & year == 1999
replace ndisp = 3.24 if country==2 & year == 1991
replace ndisp = 3.57 if country==2 & year == 1995
replace ndisp = 3    if country==2 & year == 1999
replace ndisp = 1.53 if country==3 & year == 1984
replace ndisp = 1.4  if country==3 & year == 1987
replace ndisp = 2.35 if country==3 & year == 1990
replace ndisp = 2.61 if country==3 & year == 1994
replace ndisp = 1.52 if country==3 & year == 1998
replace ndisp = 25.55 if country==4 & year == 1997
replace ndisp = 0.66 if country==6 & year == 1990
replace ndisp = 4.71 if country==6 & year == 1994
replace ndisp = 2.2  if country==6 & year == 1998
replace ndisp = 2.48 if country==7 & year == 1992
replace ndisp = 2.49 if country==7 & year == 1994
replace ndisp = 4.92 if country==9 & year == 1985
replace ndisp = 4.74 if country==9 & year == 1989
replace ndisp = 3.65 if country==9 & year == 1993
replace ndisp = 3.95 if country==9 & year == 1997
replace ndisp = 3.71 if country==9 & year == 2001

label var ndisp "Disproportionality"	



* Pure Sociodemographic Model (Table 1 of the EJPR article)
	logit erp male ageupto24 age25to34 age35to44 age45to54 age55to64 noeducprimary midschool secondaryschool  profmanager routnonman selfemployed manual [pweight=elecwe] if complete,robust cluster(country)
	
* Complete Model (Table 3 of the EJPR article)
		logit erp male ageupto24 age25to34 age35to44 age45to54 age55to64 noeducprimary midschool secondaryschool  profmanager routnonman selfemployed manual ndisp ndecentr rmm odn grcoal  asylpc asylch unemploy unmplych     [pweight=elecwe] if complete, robust cluster(country)
